import 'package:favourcate/core/model/meal_model.dart';
import 'package:favourcate/core/viewmodel/favor_view_model.dart';
import 'package:favourcate/ui/pages/detail/detail_content.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';


class GLDetailScreen extends StatelessWidget {

  static const String routeName = '/detail';


  const GLDetailScreen({ Key? key }) : super(key: key);

  @override
  Widget build(BuildContext context) {

    final meal = ModalRoute.of(context)!.settings.arguments as GLMealModel;

    return Scaffold(
      appBar: AppBar(
        title: Text(meal.title),
      ),
      body: GLDetailContent(meal),
      floatingActionButton: Consumer<GLFavorViewModel>(
        builder: (ctx, favorStore, child) {
          // 1. 判断是否收藏
          final isFavor = favorStore.isFavor(meal);
          final iconData = isFavor ? Icons.favorite : Icons.favorite_border;
          final iconColor = isFavor ? Colors.red : Colors.white;
          return FloatingActionButton(
            child: Icon(iconData, color: iconColor,),
            onPressed: () {
             favorStore.handleMeal(meal);
            },
          );
        }
      ),
    );
  }
}